<!--
 * @Author: chunlai
 * @Date: 2024-09-24 17:12:03
 * @LastEditTime: 2025-11-18 17:57:09
 * @LastEditors: minsheng_insurance_agency_zhoucl
 * @FilePath: \01.latest-short-insure\src\views\multipages\iframe.vue
 * @Description: 利宝智能健告
-->
<template>
  <div>
    <div class="iframe-container">
      <iframe
        :src="url"
        name="myiframe"
        ref="myiframe"
        id="myiframe"
        style="height: 100vh; width: 100%; margin: 0; border: 0"
      >
      </iframe>
    </div>
  </div>
</template>

<script>
import { mapGetters } from "vuex";
export default {
  name: "IframeAutoNotice",
  components: {},
  data() {
    return {
      url: "",
      pIdx: 0,
    };
  },
  computed: {
    ...mapGetters({
      iframeUrl: "notice/iframeUrl",
      mainInsu_e: "risks/mainInsu",
      assuredList: "insert/assuredList",
    }),
  },
  watch: {},
  created() {
    const querys = this.$route.query;
    this.pIdx = querys.pIdx;
    this.url = `${this.iframeUrl}${this.mainInsu_e[0].planCode}`;
    window.addEventListener("message", this.receiveMessage, false);
  },
  mounted() {},
  destroyed() {
    window.removeEventListener("message", this.receiveMessage);
  },
  methods: {
    //处理接收的消息
    receiveMessage(event) {
      let data = event.data;
      if (data.type) {
        console.log("评测结果：", data);
        let flag = "N";
        // type: 核保通过返回submit;未通过返回more
        if (data.type == "submit") {
          // 核保通过
          this.saveIframeRes(data.data);
          flag = "Y";
        }
        this.$store.commit("insert/UPDATE_ASSURED", {
          index: this.pIdx,
          data: { healthyStatus: flag },
        });
        this.$backRouter();
      }
    },
    saveIframeRes(dataList) {
      let params = {
        ...this.apiComParams,
        type: "1",
        imparts: dataList,
        idNum: this.assuredList[this.pIdx].idNum,
      };
      this.$store.dispatch("apis/comAdminApiRequest", {
        apiParams: params,
        apiName: "saveImparts",
        toast: true,
      });
    },
  },
};
</script>
<style lang="less" scoped>
.iframe-container {
  width: 100vw;
  height: 100vh;
}
</style>
